/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.pobing.service.impl;

import com.pobing.grpc.lib.hello.HelloRequest;
import com.pobing.grpc.lib.hello.HelloResponse;
import com.pobing.grpc.lib.hello.HelloServiceGrpc.HelloServiceImplBase;
import com.pobing.grpc.lib.hello.HelloServiceGrpc.HelloServiceBlockingStub;
import com.pobing.service.HelloService;
import io.grpc.Channel;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xfworld
 * @since create on 2021-06-28.
 **/
@Service
public class HelloServiceImpl extends HelloServiceImplBase implements HelloService {


    @GrpcClient("grpcSampleServer")
    private HelloServiceBlockingStub blockingStub;

    @Override
    public Map getGreeting(String name) {
        HelloResponse response = blockingStub.sayHello(HelloRequest.newBuilder().setName(name).build());
        Map map = new HashMap();
        map.put("code", response.getCode());
        map.put("msg", response.getMessage());
        return map;
    }
}
